package edu.washington.cs.workflow.recommender;

import java.util.List;

import edu.washington.cs.workflow.analysis.AnalysisBuilder.CG;
import edu.washington.cs.workflow.analysis.AnalysisBuilder.UIFramework;
import edu.washington.cs.workflow.matching.ExecutionTraceMatcher;
import edu.washington.cs.workflow.matching.ExecutionTraceMatcherFactory;
import edu.washington.cs.workflow.util.Utils;
import junit.framework.TestCase;

public class TestProportionBasedActionRecommendation extends TestCase {

	//ranks 2
	public void testCrossword() {
		String oldTrace = "./tests/demo-traces/crossword-new-puzzle-old-version.txt";
		String[] newTraces = new String[]{"./tests/files/crossword_all_actions_new_version.txt"};
		
        String[] pkgs = new String[]{"crosswordsage"};
		String oldClassPath = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\crossword-0.3.jar";
		String oldMain = "Lcrosswordsage/MainScreen";
		
		String newClassPath = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\crossword-0.3.5.jar";
		String newMain = "Lcrosswordsage/MainScreen";
		
		String handlerDesc = "crosswordsage.MainScreen$MenuListener.actionPerformed(Ljava/awt/event/ActionEvent;)V";
		List<String> actions = recommendActions(oldTrace, newTraces,
				oldClassPath, oldMain, pkgs, newClassPath, newMain, pkgs,
				UIFramework.SWING, CG.RTA, handlerDesc);
		this.showActions(actions);
	}
	
//	public void
	
	private List<String> recommendActions(String oldTrace, String[] newTraces,
			String oldClassPath, String oldMain, String[] oldPackages,
			String newClassPath, String newMain, String[] newPackages,
			UIFramework framework, CG type, String oldHandlerDesc) {
		ReplacementActionRecommender recommender = new ReplacementActionRecommender(oldTrace, newTraces);
		ExecutionTraceMatcher matcher = ExecutionTraceMatcherFactory.
		        createExecutionTraceMatcher(
				oldClassPath, oldMain, oldPackages,
				newClassPath, newMain, newPackages,
				framework, type);
		recommender.setTraceMatcher(matcher);
		
		List<String> actions = recommender.recommendActionsByProportion(oldHandlerDesc);
		return actions;
	}
	
	private void showActions(List<String> actions) {
		int count = 1;
		for(String action : actions) {
			System.out.println(count++ + ". " + action);
		}
	}
}